package com.sd.activity;

import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alex.log.ALog;
import com.sd.app.AppInit;
import com.sd.util.HtmlFinish;
import com.sd.util.SIMCardInfo;
import com.sd.util.WebUtil;
import com.sd.view.ViewUtil;

/**
 * 
 * 
 * @author Alex.Lu
 * 
 */
public class CHLMessageRechargeActivity extends BaseActivity implements
		OnClickListener, HtmlFinish {

	private LinearLayout mMainLL;
	private ScrollView scroll;
	
	private ImageButton mReturn;
	private static int mMsg;
	private EditText mPhoneNoET;
	private EditText mAmountET;
	private Button mRechargeBT;
	private TextView mTitleTV;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_recharge_message_chl);
		
		/*if(!AppInit.getInstance().getSIM().getNativePhoneNumber().equals("")
			&& AppInit.getInstance().getSIM().getProvidersName().equals("中国移动")){
			LinearLayout accountLL = (LinearLayout) findViewById(R.id.accountLL);
			accountLL.addView(ViewUtil.getAccountView(this, "account", "value"));

			mTitleTV = (TextView) findViewById(R.id.title);

			mPhoneNoET = (EditText) findViewById(R.id.phone_no);
			mPhoneNoET.setText(AppInit.getInstance().getSIM().getNativePhoneNumber());
			mAmountET = (EditText) findViewById(R.id.amount);

			mRechargeBT = (Button) findViewById(R.id.recharge);
			mRechargeBT.setOnClickListener(this);

			mReturn = (ImageButton) findViewById(R.id.return_btn);
			mReturn.setOnClickListener(this);
		}else{*/
		
			mMainLL = (LinearLayout)findViewById(R.id.recharge_main);
			mMainLL.addView(WebUtil.getWevView(this, "http://wap.qidian.cn/wap2/user/checkMobile.do?mtd=checkMobile&sid="+BookStoreActivity.user));
			mMainLL.setVisibility(View.VISIBLE);
			scroll = (ScrollView)findViewById(R.id.scrollView1);
			scroll.setVisibility(View.GONE);
			mReturn = (ImageButton) findViewById(R.id.return_btn);
			mReturn.setOnClickListener(this);
		//}
	}
	
	

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int v_id = v.getId();

		switch (v_id) {
		case R.id.return_btn:
			finish();
			break;

		case R.id.recharge:
			String phonenum = mPhoneNoET.getText().toString();
			mAmountET.getText().toString();
			
			String postUrl = "http://wap.qidian.cn/wap2/pay/unihjsmschannellist.do?mtd=unihjsmschannellist&sid=" + BookStoreActivity.user;
			StringBuffer sbuf = new StringBuffer();
			sbuf.append("mobile=");
			sbuf.append(phonenum);
			sbuf.append("&c=unicom");
			sbuf.append("&pri=2");
			ALog.e("postUrl:"+postUrl);
			WebUtil.getHtml(this,this,postUrl,sbuf.toString());
			break;
		default:
			break;
		}
	}
	
	
	private void sendSMS(String phonenum, String content) {
		if ((phonenum == null || "".equals(phonenum))
				|| (content == null || "".equals(content))) {
		} else {
			SmsManager manage = SmsManager.getDefault(); // 取得默认的SmsManager用于短信的发送
			List<String> all = manage.divideMessage(content); // 短信的内容是有限的，要根据短信长度截取。逐条发送
			Iterator<String> it = all.iterator();
			while (it.hasNext()) {
				manage.sendTextMessage(phonenum, null, it.next(), null, null); // 逐条发送短息
			}
		}

	}


	@Override
	public void onFinish(String html) {
		// TODO Auto-generated method stub
		ALog.e("onfinish:"+html);
	}


}